package icepuppet.test1;

import java.util.*;

public class HashMapCount {
    public static void main(String[] args) {
        // 80人投票选景点
        String[] arr = {"A","B","C","D"};

        ArrayList<String> list = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 80; i++) {
            int index = random.nextInt(arr.length);
//            System.out.println(arr[index]);
            list.add(arr[index]);
        }

        HashMap<String,Integer> hashMap = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            String name = list.get(i);
            if ( !hashMap.containsKey(name) ){
                hashMap.put(name,1);
            }else {
                int count = hashMap.get(name);
                count++;
                hashMap.put(name,count);
            }
        }
        System.out.println(hashMap);

        int max = 0;
        Set<Map.Entry<String, Integer>> entries = hashMap.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            int count = entry.getValue();
            if (count > max){
                max = count;
            }
        }
        System.out.println(max);

        for (Map.Entry<String, Integer> entry : entries) {
            int count = entry.getValue();
            if (count == max){
                max = count;
                System.out.println(entry.getKey());
            }
        }
        int[] a = {1,2,2,3,4,5};
        System.out.println(a.length);
    }
}
